package com.ghost.alibabaghost.exception;

/**
 * 包： com.ghost.alibabaghost.exception
 * 项目名称 alighost
 * @author yaolsa
 * 创建时间 2022/4/2 14:31
 * 描述：
 * Version 1.0
 */
public class ExceptionResult {

    /*成功标识*/
    private Boolean success;
    /*状态码*/
    private Integer code;
    /*提示信息*/
    private String msg;
    /*返回数据*/
    private Object data;

    public ExceptionResult() {
    }

    public ExceptionResult(Boolean success, Integer code, String msg, Object data) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /*自定义异常返回结果*/
    public static ExceptionResult defineError(GhostException exception){
        ExceptionResult ghostResult = new ExceptionResult();
        ghostResult.setSuccess(false);
        ghostResult.setCode(exception.getErrorCode());
        ghostResult.setMsg(exception.getErrorMsg());
        ghostResult.setData(null);
        return ghostResult;
    }

    public static ExceptionResult validError(ErrorEnum errorEnum,Object o){
        ExceptionResult ghostResult = new ExceptionResult();
        ghostResult.setSuccess(false);
        ghostResult.setCode(errorEnum.getErrorCode());
        ghostResult.setMsg(errorEnum.getErrorMsg());
        ghostResult.setData(o);
        return ghostResult;
    }

    /*其他异常返回结果*/
    public static ExceptionResult otherError(ErrorEnum errorEnum){
        ExceptionResult ghostResult = new ExceptionResult();
        ghostResult.setSuccess(false);
        ghostResult.setCode(errorEnum.getErrorCode());
        ghostResult.setMsg(errorEnum.getErrorMsg());
        ghostResult.setData(null);
        return ghostResult;
    }


    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
